package com.atguigu.gmall.juc.juc;

/**
 * @author 陈昆昆
 * @version 1.0
 * @date 2020/5/28 14:11
 */
public class VolatileView {
    /*没有加volatile*/
    private volatile  static int number = 0;
    public static void addnumber(){
        number = 60;
    }
    public static void main(String[] args) {
        new Thread(()->{
            System.out.println(Thread.currentThread().getName() + "common in");
            try { Thread.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); }
            new VolatileView().addnumber();
            System.out.println(Thread.currentThread().getName()+"update"+VolatileView.number);
        }).start();

        while (number==0){

        }
        System.out.println(Thread.currentThread().getName()+"--->"+VolatileView.number);
    }

}
